const {
    mysql,
    pool,
    router,
    Result,
    Myquery
} = require('../../connect');

// 获取所有的text数据
router.post('/upDataText', (req, res) => {
    upDataText(req, res)
})

// 插入数据
function upDataText(req, res) {
    // 取传过来的text参数
    var data = req.body;
    console.log(req.params, req.query, req.body, '参数')
    // 
    if (!data.id || !data.text || !data.name || !data.age) {
        res.json(new Result({
            code: 200,
            msg: '信息不完整'
        }))
    }
    var sql = "UPDATE node_one set name=?,age=?,text=? where id=?;";
    // 根据id查找数据
    var inserts = [data.name, data.age, data.text, data.id]
    sql = mysql.format(sql, inserts)
    new Myquery(sql, (err, r) => {
        let code = 200,
            data = r,
            msg = '成功';
        if (err) {
            code = 500;
            msg = "失败";
            data = null
        }
        res.json(new Result({
            msg,
            data,
            code
        }))
    })
}

module.exports = router